package com.server1;

import com.common.AttributeKey;
import com.common.ChannelFuture;
import com.common.ChannelInboundHandlerAdapter;
import com.common.ChannelInitializer;
import com.common.ChannelOption;
import com.common.ChannelOutboundHandlerAdapter;
import com.common.EventLoopGroup;
import com.common.NioEventLoopGroup;
import com.common.NioServerSocketChannel;
import com.common.ServerBootstrap;
import com.common.SocketChannel;

//..import com.imooc.netty.ch6.AuthHandler;
//import com.common.*;.channel.*;

/**
 * @author
 */
public final class Server {

    public static void main1(String[] args) throws Exception {
        EventLoopGroup bossGroup = new NioEventLoopGroup(2);
        EventLoopGroup workerGroup = new NioEventLoopGroup(2);

        try {
            ServerBootstrap b = new ServerBootstrap();    
            b.group(bossGroup, workerGroup)
                    .channel(NioServerSocketChannel.class)
                    .childOption(ChannelOption.TCP_NODELAY, true)
                    .childAttr(AttributeKey.newInstance("childAttr"), "childAttrValue")
                    .handler(new ServerHandler())
                    .childHandler(new ChannelInitializer<SocketChannel>() {
                        @Override
                        public void initChannel(SocketChannel ch) {
                        	ch.pipeline().addLast(new ChannelInboundHandlerAdapter());
                        	ch.pipeline().addLast(new ChannelOutboundHandlerAdapter());
                        }
                    });

            ChannelFuture f = b.bind(8888).sync();  //bind返回DefaultChannelPromise

            f.channel().closeFuture().sync();
        } finally {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }
    }
}